<?php
// +----------------------------------------------------------------------
// | Copyright (c) 2004-2015 All rights reserved.
// +----------------------------------------------------------------------
// | Author: 张盛翔
// +----------------------------------------------------------------------
// | QQ：1213857382
// +----------------------------------------------------------------------
// | Module Discript: 后端接口用户模块
// +----------------------------------------------------------------------
namespace Rest\Controller;
use Rest\Controller\BaseController;
Class UserController extends BaseController {

	// 初始化函数
	public function _initialize(){
		// 检查是否登录
		$this -> checklogin();
	}

	// 用户信息处理
	public function user()
	{
		// 已经登录
		switch ($this->_method){
			case 'get': // get请求处理代码
				if (!$_GET) {
					$data['errorcode'] = "No program parameter";
					$this -> respond("error",$data,$this->_type);
					break;
				}
				$info = $_GET['info'];
				$infoArray = explode("-",$info);
				$data = M('user') -> field($infoArray) -> where(array('account' => $_SESSION['account'] ))-> find();
				$this -> respond("success",$data,$this->_type);
				break;
			case 'put': // put请求处理代码
				break;
			case 'post': // post请求处理代码
				if (!$_POST['action'] || $_POST['action'] != "update") {
					$data['errorcode'] = "No program parameter";
					$this -> respond("error",$data,$this->_type);
					break;
				}
				$mess = $_POST;
				$update = M('user') -> where(array('account' => $_SESSION['account'] ))-> save($mess);
				if ($update) {
					$data['info'] = "更新成功";
					$this -> respond("success",$data,$this->_type);
				}else{
					$data['errorcode'] = "No program parameter";
					$this -> respond("error",$data,$this->_type);
				}
				break;
			}
	}
}